package com.clkj.xiuzheng.service;

import com.clkj.xiuzheng.dao.WarehouseMapper;
import com.clkj.xiuzheng.pojo.Company;
import com.clkj.xiuzheng.pojo.Warehouse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class WarehouseServiceImpl implements WarehouseService{

    @Autowired
    private WarehouseMapper warehouseMapper;

    @Override
    public void addWarehouse(Warehouse warehouse) {
        warehouse.setWarehouseStatus(1);
        warehouseMapper.insertSelective(warehouse);
//        warehouseMapper.addSelective(warehouse);
    }

    @Override
    public PageInfo getWarehouse(Integer pageSize, Integer pageNum,Integer companyId) {
        PageHelper.startPage(pageNum, pageSize);
        Example example = new Example(Warehouse.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("companyId",companyId);
        return new PageInfo<>( warehouseMapper.selectByExample(example));
    }

    @Override
    public void updateWarehouseDown(Integer warehouseId,Integer status) {
        Warehouse warehouse =new Warehouse();
        warehouse.setWarehouseId(warehouseId);
        warehouse.setWarehouseStatus(status);
        warehouseMapper.updateByPrimaryKeySelective(warehouse);
    }

    @Override
    public void updateWarehouseUp(Integer warehouseId) {
        warehouseMapper.updateWarehouseUp(warehouseId);
    }

    @Override
    public PageInfo getWarehouseByName(Integer pageSize, Integer pageNum, String warehouseName,Integer companyId) {
        PageHelper.startPage(pageNum, pageSize);
        Example example = new Example(Warehouse.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("companyId",companyId).andCondition(" andCondition");
        return new PageInfo<>(warehouseMapper.selectByExample(example));
    }
}
